package com.yizhang.ex;

import com.yizhang.pojo.Result;
import org.springframework.web.bind.annotation.ControllerAdvice;
import org.springframework.web.bind.annotation.ExceptionHandler;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.servlet.ModelAndView;

import java.io.IOException;

@ControllerAdvice
public class GlobalHandlerExceptionResolver {


    @ExceptionHandler(value = RuntimeException.class)
    public ModelAndView handlerRuntimeExceptionResolver(Exception e) {
        ModelAndView modelAndView = new ModelAndView();
        modelAndView.setViewName("/login.html");
        return modelAndView;
    }

    @ExceptionHandler(value = IOException.class)
    @ResponseBody
    public Result handlerIoExceptionResolver(IOException e) {
        System.out.println(e.getMessage());
        return new Result(0, "", "");
    }
}
